package com.peenongsaban.freelance.service;

import java.util.Vector;

import com.peenongsaban.freelance.bean.PostServiceBean;
import com.peenongsaban.freelance.bean.RequestServiceBean;
import com.peenongsaban.freelance.dao.MyServiceDAO;
import com.peenongsaban.freelance.dao.impl.MyServiceDAOImpl;
import com.peenongsaban.freelance.model.MyServiceModel;
import com.peenongsaban.freelance.model.PageModel;
import com.peenongsaban.freelance.utils.ConstantUtils;

public class MyServiceService {
	
	public Vector<PostServiceBean> getListMyPostService(MyServiceModel model) {
		Vector<PostServiceBean> vec = new Vector<PostServiceBean>();
		MyServiceDAO dao = new MyServiceDAOImpl();
		vec = dao.listMyPostService(model);
		return vec;
	}

	public Vector<RequestServiceBean> getListMyRequestService(MyServiceModel model) {
		
		Vector<RequestServiceBean> vec = new Vector<RequestServiceBean>();
		MyServiceDAO dao = new MyServiceDAOImpl();
		vec = dao.listMyRequestService(model);
		return vec;
	}

	public Vector<PostServiceBean> getListLastPostService() {
		Vector<PostServiceBean> list = new Vector<PostServiceBean>();
		MyServiceDAO dao = new MyServiceDAOImpl();
		list = dao.listLastPostService();
		return list;
	}

	public PageModel pagingPostService(MyServiceModel model) {
		PageModel page = new PageModel();
		MyServiceDAO dao = new MyServiceDAOImpl();
		int itemList = ConstantUtils.LIMIT_PAGING_MY_POST_SERVICE;
		int size = dao.countLlistMyPostService(model);
		int totalPage = (size / itemList);
		if (size % itemList != 0) {
			totalPage++;
		}
		if (model.getPagePostService().getPageCurrentNo() == 0) {
			page.setPageCurrentNo(1);
		} else {
			page.setPageCurrentNo(model.getPagePostService().getPageCurrentNo());
		}
		page.setTotalPage(totalPage);
		page.setListTotalRow(size);
		page.setListLastRowNo(totalPage);
		return page;
	}

	public PageModel pagingRequstService(MyServiceModel model) {
		PageModel page = new PageModel();
		MyServiceDAO dao = new MyServiceDAOImpl();
		int itemList = ConstantUtils.LIMIT_PAGING_MY_REQUEST_SERVICE;
		int size = dao.countLlistMyRequestService(model);
		int totalPage = (size / itemList);
		if (size % itemList != 0) {
			totalPage++;
		}
		if (model.getPageRequestService().getPageCurrentNo() == 0) {
			page.setPageCurrentNo(1);
		} else {
			page.setPageCurrentNo(model.getPageRequestService().getPageCurrentNo());
		}
		page.setTotalPage(totalPage);
		page.setListTotalRow(size);
		return page;
	}
	
	public int allMyPostService(String idCard){
		MyServiceDAO dao = new MyServiceDAOImpl();
		int total = dao.countAllMyPostService(idCard);
		return total;
	}
	
	public int allMyRequestService(String idCard){
		MyServiceDAO dao = new MyServiceDAOImpl();
		int total = dao.countAllMyRequestService(idCard);
		return total;
	}
}
